//
//  HHNavigationBar.m
//  oschina
//
//  Created by hjl on 16/3/31.
//  Copyright © 2016年 hjl. All rights reserved.
//

#import "HHNavigationBar.h"

@implementation HHNavigationBar

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        UIButton *leftBtn = [[UIButton alloc]init];
        [leftBtn setImage:[UIImage imageNamed:@"navigationbar-sidebar"] forState:UIControlStateNormal];
        [leftBtn addTarget:self action:@selector(leftBtnClick) forControlEvents:UIControlEventTouchUpInside];
        
        UIButton *rightBtn = [[UIButton alloc]init];
        [rightBtn setImage:[UIImage imageNamed:@"navigationbar-search"] forState:UIControlStateNormal];
        [rightBtn addTarget:self action:@selector(rightBtnClick) forControlEvents:UIControlEventTouchUpInside];
        
        [self addSubview:leftBtn];
        [self addSubview:rightBtn];

    }
    return self;
}

- (void)leftBtnClick{

}

- (void)rightBtnClick{
    
    HHLog(@"12312312312");
    UIViewController *vc = [[UIViewController alloc]init];
    vc.view.backgroundColor = [UIColor redColor];
    
    
    UINavigationController *win =[UIApplication sharedApplication].keyWindow.rootViewController.navigationController;
    
    
    [win pushViewController:vc animated:YES];
    
    //[win presentViewController:vc animated:YES completion:nil];
    
}


- (void)layoutSubviews{
    [super layoutSubviews];
    NSInteger index = 0;
    for (UIView *child in self.subviews) {
        if ([child isKindOfClass:[UIButton class]]) {
            if (index == 0) {
                child.frame = CGRectMake(15, 10, 22, 22);
            }else{
                child.frame = CGRectMake(HHWidth - 15 - 22, 10, 22, 22);
            }
            index++;
        }
    }
}

@end
